package com.king.designpatterns.hybriddesignpattern.hybriddesignpattern.observingtheintermediarypatterns;

/**
 * 产品类
 * 
 * @author king
 * @date 2021-06-14 22:28 
 */
public class Product implements Cloneable{
    /**
     * 产品名称
     */
    private String name;
    /**
     * 属性是否可以变更
     */
    private boolean canChange = false;
    /**
     * 产生一个新的产品
     */
    public Product(ProductManager manager, String name){
        // 允许建立产品
        if (manager.isCreateProduct()){
            canChange = true;
            this.name = name;
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public Product clone() {
        Product p = null;
        try {
            p = (Product)super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return p;
    }
}
